function merge(head1, head2) {
    let cur = null;
    if (!head1 || head2) {
        cur = head1 ? head1 : head2;
        return cur;
    }
    let smy = {
        val: -1,
        next: null
    };
    while(head1 || head2) {
        if (head1.val < head2.val) {
            let cur = head1.next;
            head1.next = head2;
            smy.next = head1;
            head1 = cur;
        } else {
            let cur = head2.next;
            head2.next = head1;
            smy.next = head2;
            head2 = cur;
        }
        if (!head1) {
            smy.next = head2;
            break;
        }
        if (!head2) {
            smy.next = head1;
            break;
        }
    }
    return smy.next;
}